import { chromium, devices } from "playwright";
import { logger } from "../utils/logger.js";
export class Browser {
    constructor(parameters) {
        this.context = null;
        this.devices = devices["iPhone 12 Pro Max"];
        this.pages = [];
    }
    /**打开浏览器并初始化一个页面 */
    async open() {
        try {
            const browser = await chromium.launch({ headless: false });
            this.context = await browser.newContext();
            const pages = await this.context.newPage();
            this.pages.push(pages);
            logger.info("成功打开浏览器");
            return Promise.resolve();
        } catch (error) {
            logger.error(error);
        }
    }
    /**关闭浏览器 */
    async close() {
        try {
            await this.context.close();
            logger.info("成功关闭浏览器");
            return Promise.resolve();
        } catch (error) {
            logger.error(error);
        }
    }
    /**打开一个新的页面 */
    async newPage() {
        try {
            const page = await this.context.newPage();
            this.pages.push(page);
            logger.info("成功打开新页面");
            return Promise.resolve();
        } catch (error) {
            logger.error(error);    
        }
    }
}
